import { getCompanyID, getUserDepID, getUserID, requestFunComponFiex } from '@/utils';
import { useRequest } from 'umi';
import { getBaseUrl } from '@/services/urlconst';
import { AssetListManageTab } from '../mconfig/ManageTabSwitch';
const baseUrl = getBaseUrl();
export const calculationService = (Callback: (res: Record<string, any>) => void, curRes) => {
  /**获取权限参数 */
  const queryTypeObj: Record<string, any> = AssetListManageTab(curRes);

  const request = useRequest(
    (payload: any) => {
      let reqUrl = `${baseUrl}/assetDepreciationCalculation/depreciation`;
      let params = {
        ...payload,
        ...queryTypeObj,
        operatorID: getUserID(),
        operatorDepartmentID: getUserDepID(),
        operatorCompanyID: getCompanyID(),
      };
      return requestFunComponFiex('POST', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: Callback,
    },
  );
  return {
    calculationRun: request.run,
    calculationLoading: request.loading,
  };
};
